home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asm_subr.arc / BIN16IN < prev    next >
Encoding:
Text File  |  1985-12-19  |  1.4 KB  |  46 lines

  1. ;-------------------------bin16in routine begins--------------------------+
  2. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  3. ;         page : 42
  4. ;
  5. ; NAME BIN16IN
  6. ; ROUTINE FOR conversion from ASCII binary to internal 16-bit binary
  7. ;
  8. ; FUNCTION: This routine accepts a binary number from the std input device
  9. ; and converts it to internal 16-bit binary form.
  10. ; INPUT: The individual digits of the binary number are received in ASCII
  11. ; through a call to a std I/O routine.  The valid digits are 0 and 1.  An
  12. ; ASCII code other than for a valid digit will terminate the routine.
  13. ; OUTPUT: A 16-bit Binary number is returned in the DX register.
  14. ; REGISTERS USED:  Only DX is moified.  It returns the result.
  15. ; SEGMENTS REFERENCED:  None
  16. ; ROUTINES CALLED:  STDIN
  17. ; SPECIAL NOTES: None
  18. ;
  19. ; ROUTINE TO CONVERT FROM ASCII BINARY TO INTERNAL 16-BIT BINARY
  20. ;
  21. bin16in    proc    far
  22. ;
  23.     push    ax        ; save registers
  24. ;
  25.     mov    dx,0        ; initialize dx as zero
  26. ;
  27. bin16in1:
  28.     call    stdin        ; digit comes in thru al
  29.     sub    al,30h        ; subtract 30 hex
  30.     jl    bin16in2    ; check if too low
  31.     cmp    al,1
  32.     jg    bin16in2    ; check if too high
  33.     cbw            ; convert to word
  34. ;
  35.     sal    dx,1        ; shift dx left once
  36.     add    dx,ax        ; add in digit
  37.     jmp    bin16in1
  38. ;
  39. bin16in2:
  40. ;
  41.     pop    ax        ; restore registers
  42.     ret            ; return
  43. ;
  44. bin16in    endp
  45. ;-------------------------bin16in routine ends---------------------------+
  46.